#include <GL/glew.h>
#include <GL/glut.h>
#include <Cg/cgGL.h>
#include <iostream>
#include <string>
#include "TextureFormats.h"



class Kernel {
public:
	Kernel(unsigned texSize, std::string sourceName, TextureParameter &param);
	void init();
	void calc(float *bodies, float *forces, float eps);
private:
	static void cgErrorCallback();
	void checkCgError();
void checkFramebufferStatus();
	void checkGLError();
	void initCG();
	void loadShader(std::string &fileName);
	void makeTextureset();
	void makeTexture(const GLuint texID);
	void writeToTexture(GLuint texID, float *data);
	void readFromTexture(GLuint texID, GLenum attach, float *data);

	CGcontext cgContext;
	CGprofile fragmentProfile;
	CGprogram fragmentProgram;
	CGparameter bodiesParam, forcesParam, sizeParam, epsParam;
	GLuint bodiesTexID, forcesTexID;
	std::string shaderSourceName, shaderSourceCode;
	unsigned texSize;
	TextureParameter texParam;
};



class GPGPU {
public:
	GPGPU(unsigned texSize);
	~GPGPU();
	void init(int &argc, char **argv);
private:
    void initGLUT(int &argc, char **argv);
    void initGLEW();
    void initFBO();

	unsigned texSize;
	GLuint framebuffer;
	GLuint glutWindowHandle;
};
